
<template>
  <view class="video-play">
    <image :src="videoObj.img" />
    <view class="video-tools">
      <view :class="['iconfont',muted ?'iconjingyin' :'iconshengyin']" @click="toggleMuted"> </view>
      <view class="iconfont iconzhuanfa">
        <button open-type="share"></button>
      </view>
    </view>
    <view class="video-wrap">
      <video :src="videoObj.video" objectFit="fill" :muted="muted"></video>
    </view>
    <view class="download">
      <view class="download-btn" @click="handleDownLoad">
        下载高清
      </view>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      muted: false,
      videoObj: {}
    }
  },
  onLoad() {
    this.videoObj = getApp().globalData.video
  },
  methods: {
    toggleMuted() {
      this.muted = !this.muted
    },
    async handleDownLoad() {
      await uni.showLoading({ title: '下载中' })
      const res = await uni.downloadFile({ url: this.videoObj.video })
      const { tempFilePath } = res[1]
      const res2 = await uni.saveVideoToPhotosAlbum({ filePath: tempFilePath })
      await uni.hideLoading()
      await uni.showToast({ title: '下载成功' })
    }
  }
}
</script>

<style   lang='scss' scoped>
.video-play {
  height: 100vh;
  position: relative;
  image {
    position: absolute;
    width: 100%;
    height: 100%;
    z-index: -2;
    filter: blur(20px);
  }
  .video-tools {
    display: flex;
    height: 80rpx;
    align-items: center;
    justify-content: flex-end;
  }
  .iconfont {
    position: relative;
    color: #fff;
    width: 60rpx;
    height: 60rpx;
    text-align: center;
    line-height: 60rpx;
    border-radius: 50%;
    background-color: rgba(0, 0, 0, 0.2);
    font-size: 36rpx;
    margin-right: 20rpx;
  }
  button {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    //  background-color: red;
    opacity: 0;
  }
  .video-wrap {
    display: flex;
    justify-content: center;
  }
  video {
    width: 340rpx;
    height: 620rpx;
  }
  .download {
    margin-top: 30rpx;
    display: flex;
    justify-content: center;
  }
  .download-btn {
    width: 360rpx;
    height: 80rpx;

    line-height: 80rpx;
    border: 1rpx solid #fff;
    color: #fff;
    background-color: rgba(0, 0, 0, 0.3);
    border-radius: 50rpx;
    text-align: center;
  }
}
</style>